package com.hspedu.seckill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQSeckillConfig {

    //消息队列名
    private static final String QUEUE = "seckillQueue";

    //交换机名
    private static final String EXCHANGE = "seckillExchange";

    //路由名
    private static final String ROUTE = "seckill.#";

    //加入队列名
    @Bean
    public Queue queue(){
        return new Queue(QUEUE);
    }

    //加入交换机
    @Bean
    public TopicExchange exception(){
        return new TopicExchange(EXCHANGE);
    }

    //队列名绑定交换机并指定路由
    @Bean
    public Binding binding(){
        return BindingBuilder.bind(queue()).to(exception()).with(ROUTE);
    }

}
